package com.sky.controller.admin;

import com.sky.result.Result;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController("adminShopController")
@RequestMapping("/admin/shop")
@RequiredArgsConstructor
@Slf4j
public class ShopController {
    private static final String SHOP_STATUS_KEY="SHOP_STATUS";
    private final RedisTemplate redisTemplate;

    /*
    * 设置店铺营业状态
    * */
    @PutMapping("/{status}")
    public Result setShopStatus(@PathVariable Integer status){

        log.info("店铺的状态是：{}",status == 1?"营业中": "停业中");
        redisTemplate.opsForValue().set(SHOP_STATUS_KEY,status);
        return Result.success();
    }

    /*
    * 查询店铺的营业状态
    * 从上面设置的店铺营业状态中查询
    * */
    @GetMapping("/status")
    public Result selectStatus(){
        Integer status =(Integer) redisTemplate.opsForValue().get(SHOP_STATUS_KEY);
        log.info("查看当前店铺的营业状态：{}",status == 1 ? "营业中":"停业中");
        // redisTemplate.opsForValue().set(SHOP_STATUS_KEY,status);
        return Result.success();
    }
}
